{% extends "misago/admin/generic/list.html" %}
{% load i18n misago_admin_form %}


{% block page-actions %}
<div class="col-auto page-action">
  <a href="{% url 'misago:admin:users:bans:new' %}" class="btn btn-primary btn-sm">
    <span class="fa fa-plus-circle"></span>
    {% trans "New ban" %}
  </a>
</div>
{% endblock %}


{% block table-header %}
<th>{% trans "Ban" %}</th>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 200px;">{% trans "Type" %}</th>
<th style="width: 250px;">{% trans "Expires on" %}</th>
{% for action in extra_actions %}
  <th style="width: 1px;">&nbsp;</th>
{% endfor %}
<th style="width: 1px;">&nbsp;</th>
{% endblock table-header %}


{% block table-row %}
<td class="pr-0">
  <a href="{% url 'misago:admin:users:bans:edit' pk=item.pk %}" class="item-name small">
    {{ item.banned_value }}
  </a>
</td>
<td class="badges-list">
  {% if item.registration_only %}
    <span class="badge badge-warning">
      {% trans "Registration only" %}
    </span>
  {% endif %}
  {% if item.is_expired %}
    <span class="badge badge-dark">
      {% trans "Expired" %}
    </span>
  {% endif %}
</td>
<td class="small">
  {{ item.get_check_type_display }}
</td>
<td class="small{% if item.is_expired or not item.expires_on %} text-muted{% endif %}">
  {% if item.expires_on %}
    <abbr data-timestamp="{{ item.expires_on.isoformat }}" data-format="LLL">
      {{ item.expires_on }}
    </abbr>
  {% else %}
    <em>{% trans "Never" %}</em>
  {% endif %}
</td>
{% include "misago/admin/generic/list_extra_actions.html" %}
<td>
  <div class="dropdown">
    <button class="btn btn-light btn-sm dropdown-toggle" type="button" id="item-optioms-{{ item.pk }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <i class="fas fa-ellipsis-h"></i>
    </button>
    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="item-optioms-{{ item.pk }}">
      <a class="dropdown-item" href="{% url 'misago:admin:users:bans:edit' pk=item.pk %}">
        {% trans "Edit ban" %}
      </a>
      <form action="{% url 'misago:admin:users:bans:delete' pk=item.pk %}" method="post" data-delete-confirmation="true">
        {% csrf_token %}
        <button class="dropdown-item">
          {% trans "Remove ban" %}
        </button>
      </form>
    </div>
  </div>
</td>
{% endblock %}


{% block blankslate %}
<td colspan="{{ 6|add:extra_actions_len }}">
  {% if active_filters %}
    {% trans "No bans matching criteria exist." %}
  {% else %}
    {% trans "No bans are set." %}
  {% endif %}
</td>
{% endblock blankslate %}


{% block javascripts %}
{{ block.super }}
<script type="text/javascript">
  window.misago.initConfirmation(
    "[data-delete-confirmation]",
    "{% trans 'Are you sure you want to remove this ban?' %}"
  )
</script>
{% endblock %}


{% block filters-modal-body %}
<div class="row">
  <div class="col">
    {% form_row filter_form.check_type %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.value %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.registration_only %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.state %}
  </div>
</div>
{% endblock filters-modal-body %}

